﻿using System;
using System.Net;

using System.IO;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace ALiteTeam.PackageTracer.Service
{
    [DataContract]
    public class QueryResult
    {
        private static readonly DateTime _baseTime =
            new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();

        [DataMember(Name="nu")]
        public string OrderNo { get; set; }

        [DataMember(Name = "message")]
        public string Summary { get; set; }

        [DataMember(Name = "status")]
        public byte Status { get; set; }

        [DataMember(Name = "link")]
        public string Link { get; set; }

        [DataMember(Name = "data")]
        public List<Detail> Details { get; set; }

        [DataContract]
        public class Detail
        {
            public DateTime Time { get; set; }

            public long TimeTicks
            {
                get { return (long)(Time - _baseTime).TotalMilliseconds; }
                set { Time = _baseTime.AddMilliseconds(value); }
            }

            [DataMember(Name = "time")]
            public string TimeString
            {
                get { return Time.ToString(); }
                set { Time = DateTime.Parse(value); }
            }

            [DataMember(Name = "context")]
            public string Context { get; set; }

            public DateTime FTime 
            { 
                get { return Time; }
                set { Time = value; }
            }

            public long FTimeTicks
            {
                get { return (long)(FTime - _baseTime).TotalMilliseconds; }
                set { FTime = _baseTime.AddMilliseconds(value); }
            }

            [DataMember(Name = "ftime")]
            public string FTimeString
            {
                get { return FTime.ToString(); }
                set { FTime = DateTime.Parse(value); }
            }
        }
    }
}
